from collections import deque, defaultdict

n, m = map(int, input().split())
grid = defaultdict(list)
for _ in range(m):
    u, v, w = map(int, input().split())
    grid[u].append([v, w])

minist = [float('inf')] * (n + 1)
minist[1] = 0
visited = [False] * (n + 1)
visited[1] = True
queue = deque([1])
while queue:
    curr = queue.popleft()
    visited[curr] = False  # 不在队列中
    for v, w in grid[curr]:
        if minist[curr] + w < minist[v]:
            if not visited[v]:
                queue.append(v)
                visited[v] = True  # 代表该元素已经存在于队列中
            minist[v] = minist[curr] + w

if minist[-1] != float('inf'):
    print(minist[-1])
else:
    print("unconnected")
